<?php
namespace Admin\Controller;
use Think\Controller;
class BaseController extends Controller {



   public function _initialize(){
   		$this->checkUser();
		
		
	//	cookie( "AUTH_MEMBER_STRING");exit;
		
		
		
		$this->assign('adminLock',intval(file_get_contents(__PHYSICS__.'/App/Admin/Conf/admin.lock')));  ////开发人员平台开关
		
		$m_config = M('admin_config');
		$this->assign('langLock',$m_config->getField('is_language'));  ////多语言版本开关
		$this->assign('mobilePower',$m_config->getField('is_mobile'));  ////手机站开关	
		$this->assign('htmlPower',C('CREAT_HTML'));  ////静态页开关		
		
		
		
		
		
		$m_lang = M('admin_language');
		$langList = $m_lang->order('list_order desc , id asc')->select();
		$this->assign('langList',$langList);// 赋值数据集


        
		
;
		
		
		$GLOBALS['notice'] = C('NOTICE');   /////后台相关提示语
		
		$ma = D('user');
		$mb = M('user_group');
		$m_id = $ma->getAuthInfo('id');	
		$group_id = $ma->getAuthInfo('group_id');
		$group_name = $mb->where('id='.$group_id)->getField('group_name');
		$group_keys = $mb->where('id='.$group_id)->getField('group_keys');
		$this->assign('m_id',$m_id);   ////管理员ID
		$this->assign('group_name',$group_name);   ////管理员权限组名
		$this->assign('group_keys',$group_keys);   ////管理员权限索引
		
		
		
		if($_POST){
		$user_log_url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		$user_log_data['eurl']=$user_log_url;
		$user_log_data['addtime']=date("Y-m-d  H:i:s",time());
		$user_log_data['uid']=$m_id;
		M('user_log')->add($user_log_data);
		}
		
		
		//******以下代码为前台页面进行PvPr值统计使用，请在网站前台嵌套完毕后将此段代码剪切至Home模块的根控制器的自启动方法中******//
		
/*		$mpr = M('guest_pr');
		$mpv = M('guest_pv');
		$guest['addtime'] = strtotime(date('Y-m-d'));
		$guest['ip']      = getIp();
		$mpv->add($guest);
		$isAdd = $mpr->where($guest)->getField('count(*)');
		if(!$isAdd)$mpr->add($guest);*/
		
		//******以上代码为前台页面进行PvPr值统计使用，请在网站前台嵌套完毕后将此段代码剪切至Home模块的根控制器的自启动方法中******//
		
   }

   public function checkUser(){
   		$user = D('Admin/User');
		
		$result = $user->auth();
		!$result && $this->error('请登录后操作',U('Login/index'));
		
   }
   
   public function baseDelFile($m,$ids,$field){
		$file = new \Myself\FileSystem();// 实例化上传类
		$config=C("TMPL_PARSE_STRING");//获取相关配置信息
		$pInfo = M($m)->where('id in('.$ids.')')->field($field)->select();
		foreach($pInfo as $item){
			$delpic[]=$config["__AFILE__"].$item[$field];
			$info=pathinfo($item[$field]);
			$delpic[]=$config["__AFILE__"].$info['dirname']."/thumb_".$info["basename"];
		}
		$file->rm($delpic);//删除文件
		return $delpic;
   }

	public function selectPage(){
		$paras['act'] = I('act');
		$paras['title'] = I('title');
		$paras['back_url'] = I('back_url','','strip_tags');
		$paras['jump_url'] = I('jump_url','','strip_tags');

		$this->assign('paras',$paras);
		$this->display('Inc/select_jump');
	}
	
	
	public	function oss_view($object)
		{
		
		 if(!$object){   return  ""; }
		 if(strstr($object,"user/pic")){
		 $url=__VUPLOAD__.$object;
		 }else{
		 $url=__LOADWWW__."Api.php/Get/fileview?url=".$object;
		// $endpoint.$object
		// $endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com/";
		// $url="http://jdross.oss-cn-beijing.aliyuncs.com/".$object; 
		 }
         return  $url;

		}
		

   		public	function oss_view_video($object)
		{
		
		    $temp_file = str_replace('/','',$object);
		
			$is_file="./temp/".$temp_file;	
			if(file_exists($is_file)){
		     return  __LOADWWW__."temp/".$temp_file;
			 //return 1;
		    }else{
			//$object=I('url');
			vendor('Oss.autoload');
			$accessKeyId = "m30l1H7q8FGqBAhR";
			$accessKeySecret = "esDVXQpSL35LSKgMGLP1ZdXMtDON1g";
			$endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com/";
			$bucket = "jdross";  //<您使用的存储空间名称，注意命名规范
			$ossClient = new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint,true);
			$localfile = "temp/".$temp_file;
			$options = array(
				"fileDownload" => $localfile,
			);
			try{
				$ossClient->getObject($bucket, $object, $options);
			} catch(OssException $e) {
				return ;
			}
			
		    return  __LOADWWW__."temp/".$temp_file;
	
		   }
      //   return  "http://www.judaren.com.cn/jdrapia/temp/".$filename;

		}
		





}